package com.spboot.msg.service;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.spboot.msg.entity.User;

@Service
public class MsgService {

	/**
	 * 只有一个监听的情况下
	 * 	如果有监听消息立即接收
	 * 	没有监听，消息被activeMQ存储，此时开启监听消息会按顺序接收
	 * 两个/两个以上监听
	 * 	只有其中一个接收到消息
	 * 监听消息队列的名称
	 * @param msg
	 */
	@JmsListener(destination = "user_reg_msg")
	public void userReg(String msg) {
		System.out.println("接收到的消息是:" + msg);
//		User user = JSON.parseObject(msg, User.class);
//		// 发短信 邮件
//		System.out.println(user.getEmail());
//		System.out.println(user.getPhone());
	}
	
	@JmsListener(destination = "news_topic")
	public void topicNewsA(String msg) {
		System.out.println("订阅者A接收到的消息是:" + msg);
	}
	
	@JmsListener(destination = "news_topic")
	public void topicNewsB(String msg) {
		System.out.println("订阅者B接收到的消息是:" + msg);
	}
	
	@JmsListener(destination = "news_topic")
	public void topicNewsC(String msg) {
		System.out.println("订阅者C接收到的消息是:" + msg);
	}
}
